CREATE PROCEDURE coreCmsDelete
(
	@cid				int
)
AS
BEGIN
	SET NOCOUNT ON;
	
	/* Declarations */
	DECLARE		@parentid	int;
	DECLARE		@rank		int;
	
	/* Get info about the record being removed */
	SELECT	@rank = ISNULL(Rank, -1), 
			@parentid = ISNULL(FK_ParentID, -1)
	FROM Content WHERE PK_ID=@cid;
	IF @rank = -1 RETURN;	

	/* Re-order ranks around the content being removed */
	UPDATE Content SET Rank=Rank-1 WHERE FK_ParentID=@parentid AND Rank>@rank;

	/* Delete associated records */
	DELETE FROM ContentTaxonomy WHERE FK_ContentID=@cid;
	DELETE FROM ContentPortlets WHERE FK_ContentID=@cid;
	DELETE FROM ContentWorkflow WHERE FK_ContentID=@cid;
	DELETE FROM ContentSecurity WHERE FK_ContentID=@cid;
	
	/* Finally, delete the records */	
	DELETE FROM ContentV WHERE FK_ContentID=@cid;
	DELETE FROM Content WHERE PK_ID=@cid;
	
	SET NOCOUNT OFF;	
END